package gw.com.android.ui.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.gwtsz.gts2.hx.R;

import gw.com.android.app.ActivityManager;
import gw.com.android.app.AppMain;
import gw.com.android.app.GTConfig;
import www.com.library.util.DeviceUtil;

/**
 * Created by jay on 2017/7/20.
 */
public class BackLoginDialog extends BaseDialog implements View.OnClickListener {

    public BackLoginDialog(Context context, String content) {
        super(context);
        mContent = content;
    }

    private TextView mView;
    private String mContent = "";
    /**
     * 显示弹层
     * @param act
     */
    public static void showBackLoginDialog(Activity act, String content){
        mInstance = new BackLoginDialog(act,content);
        mInstance.show();
    }
    /**
     * 显示弹层
     * @param act
     * @param content
     * @param canceleable 设置点击边缘是否可以消失
     */
    public static void showBackLoginDialog(Activity act, String content,boolean canceleable){
        mInstance = new BackLoginDialog(act,content);
        mInstance.setCanceledOnTouchOutside(canceleable);
        mInstance.show();

    }

    @Override
    public void initParam() {
        mCustomViewResId = R.layout.dialog_tourist_login_content;
        mBtnPosText = AppMain.getAppString(R.string.btn_login);
        mBtnNegText = AppMain.getAppString(R.string.btn_cancel);
        int padding = (int) (15 * DeviceUtil.instance().getScreenDensity(mOwnerAct));
        setPadding(padding, 0, padding, 0);
    }

    @Override
    public void inflaterCustomView(View mCustomView) {
        mView = (TextView) mCustomView.findViewById(R.id.dialog_content_text);
        mBtnPos.setOnClickListener(this);
        mBtnNeg.setOnClickListener(this);
        if(mContent.length() > 0){
            mView.setText(mContent);
        }
    }

    // -------------------------------------------------------------
    // Functions of OnClickListener
    // -------------------------------------------------------------
    @Override
    public void onClick(View v) {
        v.setClickable(false);
        v.setEnabled(false);
        dismiss();
        switch (v.getId()) {
            // 登录
            case R.id.action_btn_pos:
                GTConfig.instance().isPhoneLogin =false;
                GTConfig.instance().mCurLoginPhone ="";
                ActivityManager.backLogin(mOwnerAct,true);
                break;
            // 取消
            case R.id.action_btn_neg:
                dismiss();
                break;
        }
    }
}
